﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Common.Utilities.OpenXml
{
	/// <summary>
	/// Encapsulates the functionality of a PivotCacheDefinition and it's related records.
	/// </summary>
	public class PivotCacheDefinition : PackagePartBase
	{
		private PivotCacheDefinition(PackageHelper package, Uri uri)
			: base(package, uri)
		{ }

		/// <summary>
		/// Creates a new pivot cache definition part and it's association record part.
		/// </summary>
		/// <param name="package">The package to creat the part in.</param>
		/// <param name="name">The name of the new part to create.</param>
		/// <param name="data">The data to use when initializing the part's content.</param>
		/// <returns>A new instance of a PivotCacheDefinition object.</returns>
		public static PivotCacheDefinition Create(PackageHelper package, string name, byte[] data)
		{
			// create PivotCacheDefinition package part
			Uri pivotCacheDefinitionUri =
				new Uri(string.Format("/xl/pivotCache/{0}.xml", name),
						UriKind.Relative);
			package.CreateNewPart(pivotCacheDefinitionUri,
				"application/vnd.openxmlformats-" +
				"officedocument.spreadsheetml.pivotCacheDefinition+xml",
				data);

			// return the new object
			return new PivotCacheDefinition(package,
				pivotCacheDefinitionUri);
		}
	}
}
